package com.itr.kbm.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itr.kbm.dao.ListKoptelProductDao;
import com.itr.kbm.model.ListKopeg;
import com.itr.kbm.model.ListKoptelProduct;

@Repository
public class ListKoptelProductDaoImpl extends AbstractDaoImpl<ListKoptelProduct, Integer> implements ListKoptelProductDao {
	
    protected ListKoptelProductDaoImpl() {
        super(ListKoptelProduct.class);
    }
    
	public boolean checkInListKoptelProduct (String username, String password) {
				
    	Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("kodeKoptelProduct", username)); 
    	criteria.add(Restrictions.eq("password", password)); 
    	
    	List<ListKoptelProduct> list = criteria.list();
    	
    	if (list.size() == 0) {
    		return false;
    	}
    	else {
    		if (list.size() == 1) {
    			return true;
    		}
    	}
        return false;
	}
	
	public boolean checkInListKoptelProduct (String username) {
		
    	Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("kodeKoptelProduct", username)); 
    	
    	List<ListKoptelProduct> list = criteria.list();
    	
    	if (list.size() == 0) {
    		return false;
    	}
    	else {
    		if (list.size() == 1) {
    			return true;
    		}
    	}
        return false;
	}
	
	public ListKoptelProduct resetPasswordKoptelProduct (String username) {
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("kodeKoptelProduct", username));
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.get(0);
	}
	
	public ListKoptelProduct changePasswordKoptelProduct (String username, String password) {
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("kodeKoptelProduct", username));
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.get(0);
	}

	public String getKodeKoptelProduct (String namaKoptelProduct) {
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("namaKoptelProduct", namaKoptelProduct)); 
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.get(0).getKodeKoptelProduct() ;
	}
	
	public String getNamaKoptelProduct (String kodeKoptelProduct) {
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("kodeKoptelProduct", kodeKoptelProduct)); 
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.get(0).getNamaKoptelProduct() ;
	}
	
	public int getId (String kodeKoptelProduct) {
		
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("kodeKoptelProduct", kodeKoptelProduct)); 
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.get(0).getId() ;
	}
	
	public String getKodeKoptelProductss (int id) {
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.eq("id", id)); 
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.get(0).getKodeKoptelProduct() ;
	}
	
	public int getTotalKoptelProduct () {
		
		Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.isNotNull("kodeKoptelProduct")); 
    	
    	List<ListKoptelProduct> list = criteria.list();
        return list.size() ;
	}
	
    public List<ListKoptelProduct> getAllListKoptelProduct() {
      	
    	Criteria criteria = getCurrentSession().createCriteria(ListKoptelProduct.class);
    	criteria.add(Restrictions.isNotNull("kodeKoptelProduct"));
    	List<ListKoptelProduct> listKoptelProduct = criteria.list();
    	    	
    	return listKoptelProduct;
	}
	
}
